Public Sub ISmartTagRecognizer_Recognize(ByVal Text As String, ByVal DataType As SmartTagLib.IF_TYPE, ByVal LocaleID As Long, ByVal RecognizerSite As SmartTagLib.ISmartTagRecognizerSite)
' Recognize numbers followed by the symbol l or m for liters or meters.
Dim i As Integer
Dim j As Integer
Dim match As Integer
Dim index As Integer
Dim quantity As Integer
Dim termlen As Integer
Dim propbag As SmartTagLib.ISmartTagProperties
Dim words As Variant
Dim length As Integer
Dim position As Integer
' Catch any errors and display the VB error for debugging purposes.
On Error GoTo bail
' Check for characters used in word to mark empty space in the buffer.
' If any of those characters are present at the end of Text, then
' eliminate them.
length = Len(Text)
If (length > 0) Then
position = InStr(1, Text, ChrW(-4))
Else
position = 0
End If
While (length > 0 And position > 0)
Mid$(Text, position, 1) = " "
length = length - 1
If (length > 0) Then
position = InStr(1, Text, ChrW(-4))
Else
position = 0
End If
position = InStr(1, Text, ChrW(-4))
Wend
Text = RTrim(Text)
' now trim off the carriage return at the end of the string if there is one
If (Right(Text, 1) = ChrW(13)) Then
Text = Left(Text, length - 1)
End If
' Convert to lowercase to handle M the same as m
Text = LCase(Text)
' When getting data from Excel, there is no need to check anything but the
' entire string, since Excel supports only smart tags that comprise the entire
' contents of the cell.
If (DataType = IF_TYPE_CELL) Then
' Check if the whole string starts with a digit.
If (Mid(Text, 1, 1) >= "0" And Mid(Text, 1, 1) <= "9") Then
match = 0
termlen = Len(Text)
' If it starts with a digit, check if it ends with "l" or "m"
If (Mid(Text, termlen, 1) = "m") Then
match = 1
' Ask the recognizer site for a property bag.
Set propbag = RecognizerSite.GetNewPropertyBag
' Write the name of the unit
propbag.Write "unit", "meters"
' Setting the style property demonstrates how properties
' of a document viewed in a web browser can be controlled.
' When this smart tag is viewed in IE the text color will be
' navy. Note that you could also put an onclick event here or
' set other properties that will change the behavior within IE.
propbag.Write "style", "color:navy"
ElseIf (Mid(Text, termlen, 1) = "l") Then
match = 1
Set propbag = RecognizerSite.GetNewPropertyBag
propbag.Write "unit", "liters"
propbag.Write "style", "color:red"
End If
' If there is a match, commit the smart tag.
If (match = 1) Then
' If the string starts with a digit and ends with a metric unit,
' then check if all the intervening characters are also digits.
If (termlen > 1) Then
For j = 2 To (termlen - 1)
If (Mid(Text, j, 1) < "0" Or Mid(Text, j, 1) > "9") Then